Skip to content

Conversation

@timfish
Copy link
Member

@timfish timfish commented Jun 11, 2025

This PR changes both the Rust and JavaScript to error if code injection fails. Previously it would inject the diagnostics_channel require/import but then fail silently. If injection fails we need to know about and it we shouldn't modify the source.

  • OrchestrionError had all the unused error types removed and InjectionMatchFailure added
  • Instrumentation now tracks when code has been injected and is reset by reset_has_injected
  • transform now returns an error if no code injection points were found
  • wasm now throws a JavaScript error if injection fails

@timfish timfish force-pushed the timfish/feat/error-on-no-injection branch from 3ce98d0 to fa22533 Compare June 11, 2025 12:53
@timfish timfish marked this pull request as ready for review June 11, 2025 13:03
Copy link
Contributor

@jsumners-nr jsumners-nr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only kind of "review" I can do for this is to rubber stamp it.

@timfish
Copy link
Member Author

timfish commented Jun 11, 2025

The only kind of "review" I can do for this is to rubber stamp it.

Do you agree with throwing an error in this case? An alternative would be to just return the unmodified source.

@jsumners-nr
Copy link
Contributor

The only kind of "review" I can do for this is to rubber stamp it.

Do you agree with throwing an error in this case? An alternative would be to just return the unmodified source.

I don't know what the ramifications are.

Copy link
Contributor

@bizob2828 bizob2828 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change.

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasm now throws a JavaScript error if injection fails

What's the stacktrace that gets shown?

@timfish
Copy link
Member Author

timfish commented Jun 11, 2025

What's the stacktrace that gets shown?

Unfortunately it contains some wasm lines:

Error: Injection match failed
    at module.exports.__wbindgen_error_new (/Users/tim/Documents/Repositories/orchestrion-js/pkg/orchestrion_js.js:457:17)
    at wasm://wasm/00a01aba:wasm-function[3099]:0x1da003
    at wasm://wasm/00a01aba:wasm-function[2603]:0x1ccc64
    at Transformer.transform (/Users/tim/Documents/Repositories/orchestrion-js/pkg/orchestrion_js.js:283:30)
    at file:///Users/tim/Documents/Repositories/orchestrion-js/tests/wasm/tests.mjs:47:23

Open to a more useful error message is Injection match failed is not obvious enough!

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try to attach some more details about the failure to the error message, like what file/function we tried to instrument.

@timfish
Copy link
Member Author

timfish commented Jun 11, 2025

I think we should try to attach some more details about the failure to the error message, like what file/function we tried to instrument.

The user supplies the library name, version and relative path to the file so it's much easier for this to be logged in JavaScript. I was saying to @bizob2828 that we should think about wrapping the wasm API with a basic JavaScript wrapper. Passing incorrect or missing parameters can cause segfaults with no stack traces. We could also use this to give more rich/helpful errors.

There are potentially multiple injections/instrumentations to apply to a file and currently we only throw an error if none are applied. Now I'm thinking about it again, we should throw if any fail to apply because many times you will be instrumenting multiple methods in a class and if any fail it's bad news!

@timfish
Copy link
Member Author

timfish commented Jun 11, 2025

I've changed it to error if any injection points fail and the message now includes the names of the functions which it failed to find:

Error: Failed to find injection points for: ["constructor", "fetch"]
    at module.exports.__wbindgen_error_new (/Users/tim/Documents/Repositories/orchestrion-js/pkg/orchestrion_js.js:457:17)
    at wasm://wasm/00a029da:wasm-function[3103]:0x1da3a7
    at wasm://wasm/00a029da:wasm-function[2605]:0x1ccfce
    at Transformer.transform (/Users/tim/Documents/Repositories/orchestrion-js/pkg/orchestrion_js.js:283:30)
    at file:///Users/tim/Documents/Repositories/orchestrion-js/tests/wasm/tests.mjs:47:23

@timfish timfish requested a review from AbhiPrasad June 11, 2025 21:25
@timfish timfish merged commit 3fa645b into apm-js-collab:main Jun 16, 2025
1 check passed
@timfish
Copy link
Member Author

timfish commented Jun 30, 2025

Now this is merged I'm thinking of a few use cases where we might want to apply a few different instrumentations and not care about whether they ALL succeed 🤔

@timfish timfish deleted the timfish/feat/error-on-no-injection branch September 12, 2025 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants